﻿using System;
using System.Windows.Data;

namespace RavenLinqpadDriver
{
    public class GuidValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value == null
                ? null
                : value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                return new Guid((string)value);
            }
            catch (FormatException)
            {
                return null;
            }
        }
    }
}
